﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace GoShopping.Web.ProductManager
{
    public partial class TypeAttribute : System.Web.UI.Page
    {
        BLL.DicBrandBean brandOper = new GoShopping.BLL.DicBrandBean();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Master.ElementSelectedChange = GetTreeView;
                GetGVData();
            }
        }

        private void GetTreeView()
        {
            TreeView tv = Master.MasterTreeView;
            SetControlCommon.GetPrdtTreeView(tv, Server.MapPath("Navigation.xml"), "prdt");
        }
        private IList<GoShopping.Model.DicBrand> GetGVData()
        {
            extGVBrand.DataSource = brandOper.GetAllBrand();
            extGVBrand.DataBind();
            return brandOper.GetAllBrand();
        }

        protected void btnDel_Click(object sender, EventArgs e)
        {
            // 使用ArrayList记录选择的项
            ArrayList selList = new ArrayList();
            int i = 0;
            // 遍历数据集
            foreach (GridViewRow row in this.extGVBrand.Rows)
            {
                // 获取行首的CheckBox，判断是否为Checked
                CheckBox cb = (CheckBox)row.FindControl("cbSingle");
                if (cb.Checked == false)
                {
                    continue;
                }
                //// 若为Checked,将信息添加到ArrayList
                selList.Add(Convert.ToInt16(((Label)row.FindControl("lblID")).Text));
                i++;
            }
            // 若遍历完成后ArrayList为空，则表示未选中任何项，页面提示
            if (selList.Count == 0)
            {
                return;
            }
            // 调用逻辑方法，执行删除操作
            BLL.DicBrandBean dbb = new GoShopping.BLL.DicBrandBean();
            for (int j = 0; j < selList.Count; j++)
            {
                dbb.DelDicBrand(Convert.ToInt16(selList[j]));
            }
            // 重新绑定
            GetGVData();
        }

        protected void cbAll_CheckedChanged(object sender, EventArgs e)
        {
            // 遍历数据集的所有数据项
            foreach (GridViewRow row in this.extGVBrand.Rows)
            {
                // 取得数据项行首的CheckBox，使其Checked属性与表头的CheckBox同步
                CheckBox subCB = (CheckBox)row.FindControl("cbSingle");
                subCB.Checked = ((CheckBox)sender).Checked;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            brandOper.AddDicBrand(zlTxtBrandName.Text.Trim());
            // 重新绑定
            GetGVData();
        }

        protected void extGVBrand_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.extGVBrand.PageIndex = e.NewPageIndex;
            GetGVData();
        }
    }
}
